package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class JDBCDemo9 {
    public static void main(String[] args) {
        Userinfo userinfo=InputUtil.getInputObject(new Userinfo(), "华英注册");
        try (
                Connection con=DBUtil.getConnection();
                ){
            String sql="INSERT INTO userinfo(username, password,nickname,age) " +
                       "VALUES(?,?,?,?);";
            PreparedStatement ps= con.prepareStatement(sql);
            ps.setString(1, userinfo.getUsername());
            ps.setString(2, userinfo.getPassword());
            ps.setString(3,userinfo.getNickname());
            ps.setInt(4, userinfo.getAge());
            int num=ps.executeUpdate();
            if(num>0){
                System.out.println("注册成功");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }

    }
}
